/** Author: David Powell
This file produces Figure 5 + Figure A9
**/

clear all
set more off
set mat 800
set seed 8721

global dir "/jules/b/dpowell"
global DATA "${dir}/purdue/replication/DATA"
global OUTPUT "${dir}/purdue/replication/output"


use ${DATA}/finaldata


gen overdose_rate=100000*(overdose/totpop)
gen opioid_rate=100000*opioids/totpop

set scheme s2color  



****10 years
preserve
gen time=(year>1985 & year<1996) + 2*(year>=1996 & year<=2005)
gcollapse (mean) *_rate [aw=totpop], by(stf nontripl time) fast
gen tmp=overdose_rate if time==1
egen olddep=max(tmp), by(stf)
gen change=overdose_rate-olddep


gen grp=stf if nontripl==0
replace grp=6 if stf==4 | stf==41 | stf==32
replace grp=16 if stf==53 | stf==56 | stf==30 | stf==49
replace grp=17 if stf==18 | stf==19 | stf==55 | stf==26 | stf==21 | stf==29
replace grp=36 if stf==9 | stf==25 | stf==42 | stf==44 | stf==50 | stf==34
replace grp=48 if stf==5 | stf==22 | stf==35 | stf==40


separate change, by(nontripl==0)


label def stf 6 California 4 Arizona 41 Oregon 32 Nevada 1 Alabama 5 Arkansas 8 Colorado 2 Alaska 9 Connecticut 10 Delaware 11 D.C. 12 Florida 13 Georgia 15 Hawaii 16 Idaho 17 Illinois 18 Indiana 19 Iowa 20 Kansas 21 Kentucky 22 Louisiana 23 Maine 24 Maryland 25 Massachusetts 26 Michigan 27 Minnesota 28 Mississippi 29 Missouri 30 Montana 31 Nebraska 33 "New Hampshire" 34 "New Jersey" 35 "New Mexico" 36 "New York" 37 "North Carolina" 38 "North Dakota" 39 Ohio 40 Oklahoma 41 Oregon 42 Pennsylvania 44 "Rhode Island" 45 "South Carolina" 46 "South Dakota" 47 Tennessee 48 Texas 49 Utah 50 Vermont 51 Virginia 53 Washington 54 "West Virginia" 55 Wisconsin 56 Wyoming

label val stf stf



foreach nnn of numlist 6 16 17 36 48 {
graph bar change0 change1 if grp==`nnn' & time==2, graphregion(color(white)) nofill over(stf, sort(change) label(labsize(large) angle(45)) ) bar(1, bfcolor(none))    ytitle("Change in Deaths per 100,000" ,  axis(1))  legend(off)  ylabel(,nogrid)

gr export ${OUTPUT}/fig5_`nnn'.eps, replace
}
restore




****FIGURE A9
preserve
gen time=(year>1985 & year<1996) + 2*(year>=2008 & year<=2017)
gcollapse (mean) *_rate [aw=totpop], by(stf nontripl time) fast
gen tmp=overdose_rate if time==1
egen olddep=max(tmp), by(stf)
gen change=overdose_rate-olddep


gen grp=stf if nontripl==0
replace grp=6 if stf==4 | stf==41 | stf==32
replace grp=16 if stf==53 | stf==56 | stf==30 | stf==49
replace grp=17 if stf==18 | stf==19 | stf==55 | stf==26 | stf==21 | stf==29
replace grp=36 if stf==9 | stf==25 | stf==42 | stf==44 | stf==50 | stf==34
replace grp=48 if stf==5 | stf==22 | stf==35 | stf==40


separate change, by(nontripl==0)


label def stf 6 California 4 Arizona 41 Oregon 32 Nevada 1 Alabama 5 Arkansas 8 Colorado 2 Alaska 9 Connecticut 10 Delaware 11 D.C. 12 Florida 13 Georgia 15 Hawaii 16 Idaho 17 Illinois 18 Indiana 19 Iowa 20 Kansas 21 Kentucky 22 Louisiana 23 Maine 24 Maryland 25 Massachusetts 26 Michigan 27 Minnesota 28 Mississippi 29 Missouri 30 Montana 31 Nebraska 33 "New Hampshire" 34 "New Jersey" 35 "New Mexico" 36 "New York" 37 "North Carolina" 38 "North Dakota" 39 Ohio 40 Oklahoma 41 Oregon 42 Pennsylvania 44 "Rhode Island" 45 "South Carolina" 46 "South Dakota" 47 Tennessee 48 Texas 49 Utah 50 Vermont 51 Virginia 53 Washington 54 "West Virginia" 55 Wisconsin 56 Wyoming

label val stf stf



foreach nnn of numlist 6 16 17 36 48 {
graph bar change0 change1 if grp==`nnn' & time==2, graphregion(color(white)) nofill over(stf, sort(change) label(labsize(large) angle(45)) ) bar(1, bfcolor(none))    ytitle("Change in Deaths per 100,000" ,  axis(1))  legend(off)  ylabel(,nogrid)

gr export ${OUTPUT}/figA9_`nnn'.eps, replace
}
restore
